/**
 * @file contests/cf1702/b/main.cpp
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/7/10 22:03:19
 **/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int cnt[30];
int main() {
  // High rating and good luck!
  int tc;
  cin >> tc;
  while (tc--) {
    string s;
    cin >> s;
    int day = 0;
    int i = 0;
    for (day = 1;; day++) {
      set<char> t;
      while (true) {
        char ch = s[i];
        if (t.count(ch))
          i++;
        else {
          if (t.size() == 3)
            break;
          else {
            t.insert(ch);
            i++;
          }
        }
      }
      if (i >= s.size()) break;
    }
    cout << day << endl;
  }
  return 0;
}
